public class GenerateEnvironmentTest {
    
    public static DiscussionTopic__c newTopic = new DiscussionTopic__c();
    public static DiscussionForum__c newDiscussionForum = new DiscussionForum__c();
    public static DiscussionProfile__c newDiscussionProfile = new DiscussionProfile__c();
    public static DiscussionMember__c newDiscussionMember = new DiscussionMember__c();
    public static DiscussionMessage__c newMessage = new DiscussionMessage__c();
    public static DiscussionForumSubscription__c newSubs = new DiscussionForumSubscription__c();
    public static User newUser = new User();	
    
    
    //Boolen for run minimal date gen
    public static Boolean runLite = false;
    
    public static testMethod void gen(){

			
        			TeamUtil.setIsTest( true ); 
        
        
        if (!TeamUtil.alreadyGenEnv) { 
	
			TeamUtil.setIsTest( true ); 
    
            // Create a new Forum Administrator Profile
            newDiscussionProfile.Name = 'DiscussionForum Administrator';
            newDiscussionProfile.ManageDiscussionForums__c = true; 
            newDiscussionProfile.PostDiscussionTopicReplies__c = true; 
            newDiscussionProfile.CreateDiscussionTopics__c = true; 
            upsert newDiscussionProfile;

			DiscussionProfile__c newDiscussionProfilePublic = new DiscussionProfile__c(); 
            newDiscussionProfilePublic.Name = 'Public Profile';
            newDiscussionProfilePublic.PostDiscussionTopicReplies__c = true; 
            upsert newDiscussionProfilePublic;            
            
			DiscussionProfile__c newDiscussionProfileMember = new DiscussionProfile__c(); 
            newDiscussionProfileMember.Name = 'Member Profile';
            newDiscussionProfileMember.PostDiscussionTopicReplies__c = true; 
            upsert newDiscussionProfileMember;             
            
			Attachment attach = new Attachment();
            attach.Name = 'Test';
            attach.Body = Blob.valueOf('Content');
            attach.ParentId = newDiscussionProfile.Id;
            insert attach;            
            
            // Create a new Forum
            newDiscussionForum.Name = 'Test class Discussion';
            newDiscussionForum.NewMemberProfile__c = newDiscussionProfile.Id;
            newDiscussionForum.PictureId__c = attach.Id;
            newDiscussionForum.Description__c = 'Discussion description';
            newdiscussionForum.MessageCount__c = 2;
            upsert newDiscussionForum;  
            
            // Create a new User
            newUser = [ SELECT Id, Name FROM User LIMIT 1 ];
            // Create a new Discussion Member
            newDiscussionMember.DiscussionProfile__c = newDiscussionProfile.Id;
            newDiscussionMember.User__c = newUser.Id;
            newDiscussionMember.DiscussionForum__c = newDiscussionForum.Id;
            upsert newDiscussionMember;

			TeamUtil.setIsTest( true ); 
            
            //Create a new Discussion Topic
            newTopic.Subject__c = 'Foo Topic';  
            newTopic.DiscussionForum__c = newDiscussionForum.Id;
            upsert newTopic;
    		
            // Create the First Discussion Message 
            newMessage.DiscussionTopic__c = newTopic.Id;
            newMessage.Discussion__c = newDiscussionForum.Id;
            newMessage.Message__c = 'Foo Text';     
            newMessage.PostedBy__c = newUser.Id;
            newMessage.PostedDate__c = System.now();
            upsert newMessage;

		    // New subscription
		    newSubs.DiscussionNewReply__c = true;
		    newSubs.DiscussionNewTopic__c = true;
		    newSubs.DiscussionReplyToMe__c = true;
		    newSubs.Team__c = newDiscussionForum.Id;
		    newSubs.TeamMemberJoinLeave__c = true;
		    newSubs.TeamMemberStatusUpdated__c = true;
		    newSubs.User__c = newUser.Id;
            //
            TeamUtil.alreadyGenEnv = true;
            
        }
    }
}